from PyQt5 import QtGui, QtWidgets
from PyQt5.QtCore import Qt
from ui.mainArea import Ui_MainWindowa
from controller.counter import CounterWindow


class MainWindow2(QtWidgets.QMainWindow, Ui_MainWindowa):
    counterWindow: CounterWindow

    def __init__(self):
        super(MainWindow2, self).__init__()
        self.setupUi(self)
        self.bt1.clicked.connect(self.click_pushButton_1)  # 点击 pushButton_1 触发
        self.bt2.clicked.connect(self.click_pushButton_2)  # 点击 pushButton_2 触发
        # 子窗口实例化
        self.counterWindow = CounterWindow()

    # 点击 bt1 触发
    def click_pushButton_1(self):
        self.counterWindow.showFullScreen()

        value = self.label.text()
        value2 = self.lineEdit_2.text()
        self.counterWindow.dataPass(value)
        self.counterWindow.dataPass2(value2)
        return

    # 点击 bt2 触发
    def click_pushButton_2(self):
        self.lineEdit_2.clear()
        return

    def keyPressEvent(self, event: QtGui.QKeyEvent):
        print("按下：" + str(event.key()))

        if (event.key() == 16777220):
            self.counterWindow.showFullScreen()

            value = self.label.text()
            value2 = self.lineEdit_2.text()
            self.counterWindow.dataPass(value)
            self.counterWindow.dataPass2(value2)
            print('测试：Enter')
        if (event.key() == Qt.Key_Escape):
            self.lineEdit_2.clear()
            print('测试：Esc')
        if (event.key() == Qt.Key_F1):
            print('测试：F1')
            self.close()

    '''
        数据传递
    '''

    def dataPass(self, data):
        self.label.setText(data)